// TOWN SCRIPT
//    Town 3: Second Floor

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documentation. States you write
// yourself should be numbered from 10-100.

// flags:
//

begintownscript;

variables;

short choice;

body;

beginstate INIT_STATE;
	turn_off_training(TRUE);
	set_crime_tolerance(5);

	// reset flags
	set_flag(3, 10, 0);
	set_flag(3, 11, 0);
	set_flag(3, 12, 0);
	set_flag(3, 13, 0);

	// restore vortex if summoned, but not killed
	if ((get_flag(3, 0) > 0) && (get_flag(101, 0) == 0))
		spawn_creature(6);
	if ((get_flag(3, 1) > 0) && (get_flag(101, 1) == 0))
		spawn_creature(7);
	if ((get_flag(3, 3) > 0) && (get_flag(101, 2) == 0))
		spawn_creature(8);
break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;
break;

beginstate 10;
	block_entry(TRUE);
	move_to_new_town(1, 18, 34);
break;

beginstate 11;
	block_entry(TRUE);
	move_to_new_town(4, 27, 14);
break;

beginstate 12;
	if ((has_item(462)) && (get_flag(50, 6) > 0)) {
		if ((get_flag(3, 0) == 0) && (get_flag(3, 10) == 0)) {
			set_flag(3, 10, 1);
			reset_dialog();
			add_dialog_str(0, "Do you use your flute and try to unfreeze a vortex?", 0);
			add_dialog_choice(0, "Yes");
			add_dialog_choice(1, "No");
			choice = run_dialog(1);
			if (choice == 1) {
				set_flag(3, 0, 1);
				message_dialog("With a short little flute note, you hear a loud whoosh start up on the other side of the door.", "Oh, oh...");
				spawn_creature(6);
			}
		}
	}
break;

beginstate 13;
	if ((has_item(462)) && (get_flag(50, 6) > 0)) {
		if ((get_flag(3, 1) == 0) && (get_flag(3, 11) == 0)) {
			set_flag(3, 11, 1);
			reset_dialog();
			add_dialog_str(0, "Do you use your flute and try to unfreeze a vortex?", 0);
			add_dialog_choice(0, "Yes");
			add_dialog_choice(1, "No");
			choice = run_dialog(1);
			if (choice == 1) {
				set_flag(3, 1, 1);
				message_dialog("With a short little flute note, you hear a loud whoosh start up on the other side of the door.", "Uh, now what...");
				spawn_creature(7);
			}
		}
	}
break;

beginstate 14;
	if ((has_item(462)) && (get_flag(50, 6) > 0)) {
		if ((get_flag(3, 2) == 0) && (get_flag(3, 12) == 0)) {
			set_flag(3, 12, 1);
			reset_dialog();
			add_dialog_str(0, "Do you use your flute and try to unfreeze a vortex?", 0);
			add_dialog_choice(0, "Yes");
			add_dialog_choice(1, "No");
			choice = run_dialog(1);
			if (choice == 1) {
				set_flag(3, 2, 1);
				message_dialog("You play a short note on the flute, but nothing seems to happen.", "You try again, but still nothing is moving behind the door...");
			}
		}
	}
break;

beginstate 15;
	if ((has_item(462)) && (get_flag(50, 6) > 0)) {
		if ((get_flag(3, 3) == 0) && (get_flag(3, 13) == 0)) {
			set_flag(3, 13, 1);
			reset_dialog();
			add_dialog_str(0, "Do you use your flute and try to unfreeze a vortex?", 0);
			add_dialog_choice(0, "Yes");
			add_dialog_choice(1, "No");
			choice = run_dialog(1);
			if (choice == 1) {
				set_flag(3, 3, 1);
				message_dialog("With a short little flute note, you hear a loud whoosh start up on the other side of the door.", "Ah, yet another one...");
				spawn_creature(8);
			}
		}
	}
break;

// state to test the end game animation quicker with...
beginstate 16;
	set_flag(100, 0, 4);
break;
